﻿import pygame
from pygame import Rect
from pygame.locals import *
from sys import exit
 
AMERICA_DO_SUL_X = 0 
AMERICA_DO_SUL_Y = 0 

OCEANIA_X = 0 
OCEANIA_Y = 0 

AFRICA_X = 0 
AFRICA_Y = 0 

AMERICA_DO_NORTE_X = 0 
AMERICA_DO_NORTE_Y = 0 

EUROPA_X = 0 
EUROPA_Y = 0 

AMERICA_DO_SUL = 'america_do_sul'
OCEANIA = 'oceania'
AFRICA = 'africa'
AMERICA_DO_NORTE = 'america_do_norte'
EUROPA = 'europa'

COUNTRIES = {}
COUNTRIES['venezuela'] = [AMERICA_DO_SUL, (10, 0)]
COUNTRIES['bolivia'] = [AMERICA_DO_SUL, (0, 51)]
COUNTRIES['brasil'] = [AMERICA_DO_SUL, (32, 33)]
COUNTRIES['argentina'] = [AMERICA_DO_SUL, (59, 147)]

COUNTRIES['sumatra'] = [OCEANIA, (0, 30)]
COUNTRIES['borneo'] = [OCEANIA, (60, 0)]
COUNTRIES['nova_guine'] = [OCEANIA, (151, 29)]
COUNTRIES['australia'] = [OCEANIA, (64, 77)]

COUNTRIES['argelia'] = [AFRICA, (0, 0)]
COUNTRIES['egito'] = [AFRICA, (109, 19)]
COUNTRIES['sudao'] = [AFRICA, (126, 65)]
COUNTRIES['congo'] = [AFRICA, (107, 148)]
COUNTRIES['africa_do_sul'] = [AFRICA, (119, 223)]
COUNTRIES['madagascar'] = [AFRICA, (244, 232)]

COUNTRIES['alaska'] = [AMERICA_DO_NORTE, (1, 63)]
COUNTRIES['mackenzie'] = [AMERICA_DO_NORTE, (86, 61)]
COUNTRIES['vancouver'] = [AMERICA_DO_NORTE, (94, 110)]
COUNTRIES['ottawa'] = [AMERICA_DO_NORTE, (206, 121)]
COUNTRIES['labrador'] = [AMERICA_DO_NORTE, (266, 98)]
COUNTRIES['california'] = [AMERICA_DO_NORTE, (75, 151)]
COUNTRIES['nova_york'] = [AMERICA_DO_NORTE, (144, 165)]
COUNTRIES['mexico'] = [AMERICA_DO_NORTE, (86, 232)]
COUNTRIES['groenlandia'] = [AMERICA_DO_NORTE, (359, 0)]

COUNTRIES['inglaterra'] = [EUROPA, (20, 31)]
COUNTRIES['islandia'] = [EUROPA, (0, 6)]
COUNTRIES['franca'] = [EUROPA, (41, 83)]
COUNTRIES['alemanha'] = [EUROPA, (90, 54)]
COUNTRIES['polonia'] = [EUROPA, (120, 67)]
COUNTRIES['moscou'] = [EUROPA, (150, 4)]
COUNTRIES['suecia'] = [EUROPA, (99, 0)]


def load(continent, countries):
    images = {}
    positions = {}
    for p in countries :
        images[p] = pygame.image.load('images/'+continent+'/'+p+'.png').convert_alpha()
        positions[p] = {'x':COUNTRIES[p][1][0], 'y':COUNTRIES[p][1][1]}
    
    return images, positions
    
def paint(screen,countries,images,positions) :
    for p in countries :
        screen.blit(images[p],(positions[p]['x'], positions[p]['y']))
        
def filtro(x) :
    return COUNTRIES[x][0] is EUROPA        
 
def main() :
    pygame.init()
    screen = pygame.display.set_mode((512,512), 0, 32)
    pygame.display.set_caption('War')

    background_image = pygame.image.load('images/background.png').convert()    
    
    countries = filter(filtro, COUNTRIES)
    images, positions = load(EUROPA, countries)

    while True :

        for event in pygame.event.get() :
            if event.type == QUIT :
                exit(0)
            if event.type == KEYDOWN and event.key == K_ESCAPE:
                exit(0)                
                
        screen.blit(background_image,(0,0))
        paint(screen, countries, images, positions)
        
        pygame.display.update()
        
if __name__ == '__main__' :
    main()